package kr.couponplay.android.activity;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;

public class TitleBarHelper {
	private static FrameLayout frameLayout;
	private static List<TitleLayout> titleLayouts = new ArrayList<TitleLayout>();
	private static TabHost tabHost;
	
	public static enum TabMenuType {
		MAIN, RECENT, MESSAGE, SEARCH;
	}
	
	public static void addTitleLayout(TitleLayout titleLayout) {
		if (frameLayout != null) {
			frameLayout.addView(titleLayout.getLinearLayout());
		}
		if (!titleLayouts.contains(titleLayout)) {
			titleLayouts.add(titleLayout);
		}
	}
	
	public static FrameLayout getFrameLayout() {
		return frameLayout;
	}

	public static void setFrameLayout(FrameLayout frameLayout) {
		TitleBarHelper.frameLayout = frameLayout;
		for (TitleLayout titleLayout : titleLayouts) {
			TitleBarHelper.frameLayout.addView(titleLayout.getLinearLayout());
		}
	}	
	
	public static void setVisibable(TabMenuType tabMenuType) {
		for (TitleLayout titleLayout : titleLayouts) {
			if (titleLayout.getTabMenuType() == tabMenuType) {
				titleLayout.getLinearLayout().setVisibility(View.VISIBLE);
			} else {
				titleLayout.getLinearLayout().setVisibility(View.GONE);
			}
		}
	}
	
	public static class TitleLayout {
		private LinearLayout titleLayout;
		private TabMenuType tabMenuType;
		
		public TitleLayout(LinearLayout titleLayout, TabMenuType tabMenuType) {
			this.titleLayout = titleLayout;
			this.tabMenuType = tabMenuType;
		}

		public LinearLayout getLinearLayout() {
			return titleLayout;
		}

		public TabMenuType getTabMenuType() {
			return tabMenuType;
		}
	}

	public static TabHost getTabHost() {
		return tabHost;
	}

	public static void setTabHost(TabHost tabHost) {
		TitleBarHelper.tabHost = tabHost;
	}

	public static void clear() {
		titleLayouts.clear();
		frameLayout.removeAllViews();
		frameLayout = null;
	}
}
